const typeorm = require('typeorm');
const { Photo } = require('./model/Photo');

start = async () => {
    const config = {
        type: "mysql",
        host: "xx",
        port: 3306,
        username: "root",
        password: "xx",
        database: "xx",
        synchronize: true,
        logging: true,
        entities: [
            require("./entity/PhotoEntity")
        ]
    };
    const connection = await typeorm.createConnection(config);

    let photo = new Photo();
    photo.name = 'flower';
    photo.description = 'test';
    photo.filename = 'flower.jpg';
    photo.views = 1000;
    photo.isPublished = false;

    let savedPhoto = await connection.manager.save([photo]);
    console.log(savedPhoto);

    const photoRepository = await connection.getRepository(Photo);
    const photos = await photoRepository.find();
    console.log(photos);
}

start();